<%--
  Created by IntelliJ IDEA.
  User: wj
  Date: 2018-11-21
  Time: 16:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/static/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/font-awesome.min93e3.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/animate.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/style.min862f.css" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/hplus/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script>
        //得到查询的参数
        function queryParams (params) {

        };

        $(function () {
            $("#hytb").bootstrapTable({
                url:'${pageContext.request.contextPath}/huiyuan/querySearch',
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                //启用服务器端分页
                sidePagination:'server',
                //设置每页多少条数据
                pageSize:2,
                pageList:[2,4,8,16],
                height:300,
                pageNumber:1,
                //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果 queryParamsType = 'limit' ,返回参数必须包含
                //limit, offset, search, sort, order 否则, 需要包含:
                //pageSize, pageNumber, searchText, sortName, sortOrder.
                // 返回false将会终止请求。
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        hname:$("#hname").val()
                    };
                    return temp;
                },

                columns:[
                    {
                        field:'hid',
                        title:'会员账号'
                    },
                    {
                        field:'hname',
                        title:'会员姓名'
                    },
                    {
                        field:'hyue',
                        title:'会员余额'
                    },

                    {
                        field:'hphone',
                        title:'会员电话'
                    },
                    {
                        field:'haddress',
                        title:'会员地址'
                    },
                    {
                        field:'huiyuanjibie.hqname',
                        title:'会员等级',
                        /*   formatter:function(value,row,index){
                               if(row.hqid==1){
                                   return"普通会员";
                               }else if(row.hqid==2){
                                   return"高级会员";
                               }
                           }*/
                    },
                    {
                        title:'操作',
                        formatter:function(value,row,index){
                            return"<button class='btn tn-primary' onclick='javascript:del("+row.hid+")' >删除</button>"+"&nbsp;&nbsp;&nbsp;&nbsp;"+
                                "<button class='btn tn-primary' onclick='javascript:ud("+row.hid+")'>修改</button>"
                        }
                    }

                ]
            }) ;
        }) ;


        function searcha() {
            var opts = $("#hytb").bootstrapTable("getOptions") ;
            var limit = opts.pageSize;
            var offset = (opts.pageNumber-1) * limit;
            var hname = $("#hname").val() ;
            $.post('${pageContext.request.contextPath}/huiyuan/querySearch',{'hname':hname,'limit':limit,'offset':offset},function (data) {
                // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#hytb").bootstrapTable('load',data) ;
            })
        }


        function doadd(){

            var hname=$("#Div3 [name=hname]").val();
            var hyue=$("#Div3 [name=hyue]").val();
            var hphone=$("#Div3 [name=hphone]").val();
            var haddress=$("#Div3 [name=haddress]").val();
            var hqid=$("#Div3 [name=hy]").val();

            $.post('${pageContext.request.contextPath}/hyInfo/inst',{'hname':hname,'hyue':hyue,'hphone':hphone,'haddress':haddress,'hqid':hqid},function(data){
                if(data>0){
                    // var mydata = eval("("+data+")") ;
                    //重新绑定表格数据
                    searcha();
                    $("#hytb").bootstrapTable("load",data);
                    $("#Div3").modal('hide');
                }
            });
        }


        function ud(hid1){
            hid=hid1;
            //发送post请求
            $.post('${pageContext.request.contextPath}/hyInfo/getqueryId',{'hid':hid},function(data){
                $("#Div2").modal('show');
                //绑定事件
                $("#Div2").on('shown.bs.modal',function(e){
                    //给表单赋值
                    $("[name=hname]").val(data.hname);

                    $("[name=hyue]").val(data.hyue)
                    $("[name=hphone]").val(data.hphone);
                    $("[name=haddress]").val(data.haddress);
                    $("[name=hy]").val(data.hqid);

                })
            })


        };

        function doupd(){
            var hname=$("#Div2 [name=hname]").val();

            var hyue=$("#Div2 [name=hyue]").val();
            var hphone=$("#Div2 [name=hphone]").val();
            var haddress=$("#Div2 [name=haddress]").val();
            var hqid=$("#Div2 [name=hy]").val();

            $.post('${pageContext.request.contextPath}/hyInfo/xg1',{"hid":hid,'hname':hname,'hyue':hyue,'hphone':hphone,'haddress':haddress,'hqid':hqid},function(data){
                if(data>0){
                    searcha();
                    $("#hytb").bootstrapTable('load',data) ;
                    $("#Div2").modal('hide');

                };
            });
        }


        var hid;
        function del(hids){
            hid=hids;
            $("#Div1").modal('show');
        }

        function dodel(){
            var opts = $("#hytb").bootstrapTable("getOptions") ;
            //发送post请求
            $.post('${pageContext.request.contextPath}/hyInfo/delet',{hid:hid},function(data){

                if(data>0){
                    $("#Div1").modal('hide');
                    $("#hytb").bootstrapTable('load',data) ;
                    searcha();
                }else{
                    alert("删除失败");
                }

            });
        }


    </script>
</head>
<body>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">会员列表</h3>
    </div>
    <div class="panel-body">
        <div class="row" style="margin-bottom: 10px">
            <form action="" class="form-inline">
                <div class="col-sm-4">
                    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#Div3">
                        <span class="glyphicon glyphicon-plus"></span>增加
                    </button>
                </div>

                <div class="col-sm-4 col-sm-offset-4 text-right">

                    <input id="hname" type="text" class="form-control">
                    <input onclick="searcha()" type="button" class="btn btn-primary" value="查询">


                </div>
            </form>
        </div>
        <table id="hytb" class="table table-bordered"></table>
    </div>
</div>



<!-- Modal -->
<div class="modal fade" id="Div1">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="modelTitleId">提示信息</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-6" id="addrole" style="height: 100px">
                        <p>确认删除该会员信息吗？</p>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="dodel()">删除</button>
            </div>
        </div>
    </div>
</div>

<%--修改模态框--%>
<div class="modal fade" id="Div2">
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">修改会员信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" method="post" >

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">会员名称:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="hname" class="form-control" id="title"  placeholder="请输入会员名称">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">会员级别</label>
                        <div class="col-sm-10">
                            <select  class="form-control" name="hy">
                                <option value="1">普通会员</option>
                                <option value="2">高级会员</option>
                                <option value="3">非会员</option>

                            </select>

                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">会员余额:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="hyue" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="会员账号">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">会员电话:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="hphone" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="会员电话">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">会员地址:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="haddress" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="会员电话">
                        </div>
                    </div>






                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" onclick="doupd()">修改</button>
                    </div>
                </form>
            </div>
        </div>
    </div>


</div>
<%--增加模态框--%>

<div class="modal fade" id="Div3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" >
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">增加会员信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" method="post" >

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">会员名称:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="hname" class="form-control" id="title1" placeholder="请输入会员名称">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">会员等级</label>
                        <div class="col-sm-10">
                            <select  class="form-control" name="hy">
                                <option value="0">请选择</option>
                                <option value="1">普通会员</option>
                                <option value="2">高级会员</option>
                                <option value="2">非会员</option>

                            </select>

                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">会员余额:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="hyue" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="请输入会员余额">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">会员电话:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="hphone" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="请输入会员电话">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">会员地址:</label>
                        <div class="col-sm-10">
                            <input  type="text" name="haddress" class="form-control" &lt;%&ndash;id="title"&ndash;%&gt; placeholder="请输入会员地址">
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary"  onclick="doadd()" >增加</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


</body>
</html>
